/*
 * SearchDialog.java
 *
 * Created on 26. Februar 2008, 15:50
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package de.blitzcoder.collide.gui;

import java.awt.event.ActionListener;
import javax.swing.*;
import java.awt.*;

/**
 *
 * @author blitzcoder
 */
public class SearchDialog extends IDEFrame {
    
    private JTextField  searchTextField;
    private JTextField  replaceTextField;
    
    private JButton     searchBtn;
    private JButton     replaceBtn;
    private JButton     replaceAllBtn;
    
    private JCheckBox   backwardsCheckBox;
    private JCheckBox   restartTopCheckBox;
    private JCheckBox   caseSensetiveCheckBox;
    private JCheckBox   keepWindowCheckBox;
    
    /** Creates a new instance of SearchDialog */
    public SearchDialog() {
        super("Suchen");
        createInterface();
    }
    
    private void createInterface() {
        
        setResizable(false);
        
        // Set up Layout
        this.setLayout(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();
        Insets insets = new Insets(3,3,3,3);
        
        // create the Gadgets
        searchTextField = new JTextField();         searchTextField.setPreferredSize( new Dimension(200,20) );
        replaceTextField = new JTextField();        replaceTextField.setPreferredSize( new Dimension(200,20) );
        searchBtn = new JButton("Suchen");
        replaceBtn = new JButton("Ersetzen & Suchen");
        replaceAllBtn = new JButton("Alle Ersetzen");
        keepWindowCheckBox = new JCheckBox("Fenster offen lassen");
        backwardsCheckBox = new JCheckBox("Rückwärts suchen");
        restartTopCheckBox = new JCheckBox("Oben erneut anfangen");
        caseSensetiveCheckBox = new JCheckBox("Groß-/Kleinschreibung");
        
        replaceBtn.setEnabled(false);
        
        // Add the Gadgets
        add(new JLabel("Suchen nach:"),0,0,1.0,0.0,c.BOTH,2,insets);
        add(searchTextField,1,0,1.0,0.0,c.BOTH,2,insets);
        add(searchBtn,3,0,0.0,0.0,c.BOTH,1,insets);
        
        add(new JLabel("Ersetzen mit:"),0,1,1.0,0.0,c.BOTH,2,insets);
        add(replaceTextField,1,1,1.0,0.0,c.BOTH,2,insets);
        add(replaceBtn,3,1,0.0,0.0,c.BOTH,1,insets);
        
        add(backwardsCheckBox,0,2,0.0,0.0,c.BOTH,1,insets);
        add(restartTopCheckBox,1,2,0.0,0.0,c.BOTH,1,insets);
        add(replaceAllBtn,3,2,0.0,0.0,c.BOTH,1,insets);
        
        add(caseSensetiveCheckBox,0,3,0.0,0.0,c.BOTH,1,insets);
        add(keepWindowCheckBox,1,3,0.0,0.0,c.BOTH,1,insets);
        
        
        
        this.pack();
    }
    
    public void add(Component component,int gridx,int gridy,double weightx,double weighty,int fill,int gridwidth,Insets insets) {
        GridBagConstraints c = new GridBagConstraints();
        c.gridx = gridx;
        c.gridy = gridy;
        c.gridwidth = gridwidth;
        c.weightx = weightx;
        c.weighty = weighty;
        c.insets = insets;
        c.fill = fill;
        this.add(component,c);
    }
    
    // Get Method
    public boolean keepWindow() { return keepWindowCheckBox.isSelected(); }
    public boolean backwards() { return backwardsCheckBox.isSelected(); }
    public boolean caseSensetive() { return caseSensetiveCheckBox.isSelected(); }
    public boolean restartOnTop() { return restartTopCheckBox.isSelected(); }
    public String  getSearchText() { return searchTextField.getText(); }
    public String  getReplaceText() { return replaceTextField.getText(); }

    public void addSearchButtonListener(ActionListener lis) {
        searchBtn.addActionListener(lis);
    }
    public void addSearchAndReplaceButtonListener(ActionListener lis) {
        replaceBtn.addActionListener(lis);
    }
    public void addReplaceAllButtonListener(ActionListener lis) {
        replaceAllBtn.addActionListener(lis);
    }
    public void setReplaceBtnEnable(boolean state) {
        replaceBtn.setEnabled(state);
    }
}
